#include "MStar.h"


MStar::MStar(float ar1, float ar2, float ah, float aox, float aoy, float aoz)
{
	name = "Star";
	verts = NULL;
	bNormal = false;
	updateStar(ar1,ar2,ah,aox,aoy,aoz);
}


MStar::~MStar(void)
{

}

void MStar::drawShape() {
	
}

MStar *MStar::makeStar(float ar1, float ar2, float ah, float aox, float aoy, float aoz) {
	if(ar1<0 || ar2 < 0 || ah<0 || ar1 > ar2) {
		return NULL;
	}
	MStar *Star = new MStar(ar1, ar2,ah,aox,aoy,aoz);
	return Star;
}

void MStar::updateStar(float ar1, float ar2, float ah, float aox, float aoy, float aoz) {
	if(ar1<0 || ar2 < 0 || ah<0 || ar1 > ar2) {//at least 1 radial stacks and 4 vertical slice
		return;
	}
	//delete old array
	if(verts) {
		delete []verts;
	}

	ox = aox;
	oy = aoy;
	oz = aoz;
	r1 = ar1;
	r2 = ar2;
	h = ah;
	step = 1;
	//create array
	const float angle = (float)36/180*PI;
	const float theta = -2*PI/5;
	verts = new MVertex[12];
	
	//populate data
	verts[0] = MVertex(0,h,0);
	verts[1] = MVertex(0,-h,0);
	verts[2] = MVertex(-r2,0,0);
	verts[3] = MVertex(-cos(angle)*r1,0,-sin(angle)*r1);
	for(int i = 2; i<6; i++) {
		verts[i*2] = verts[(i-1)*2].rotateY(theta);
		verts[i*2+1] = verts[i*2-1].rotateY(theta);
	}
}

/*func is a function to draw triangles*/
void MStar::drawStar(void(*func)(const MVertex &p1,  const MVertex &p2, const MVertex &p3, int ic),
	void(*drawline)(const MVertex &p1,  const MVertex &p2,int ic)) {
		static const int icolor = 5;
		if(!func) {	//return function
			return;
		}
		int i, j;
		int ic = 3;
		for(i=2;i<12;i++) {
			int nexti = (i==11?2:i+1);
			func(verts[i],verts[0],verts[nexti],ic);
			func(verts[i],verts[1],verts[nexti],ic);
		}
}


void MStar::incrementSlice() {

}

void MStar::decrementSlice() {

}

void MStar::incrementStack() {

}

void MStar::decrementStack() {

}
